package com.ali.juejin.widget

import android.content.Context
import android.util.AttributeSet
import android.widget.Switch
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.ali.juejin.bean.CategoryItemBean

class TagSwitch:Switch {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    companion object {

        @BindingAdapter("selectedTagList","tagId")
        @JvmStatic
        fun setSelectedTag(view: Switch, selectedTag:ArrayList<CategoryItemBean>?, tagId:String){
            selectedTag?.let {
                val tempList = it.filter { item->item.id.equals(tagId) }
                if(tempList.size == 0){
                    view.isChecked = false
                }else{
                    view.isChecked = true
                }
            }
        }
    }
}